import http from '/@lib/utils/http/request'
import { RoleDeptTree, RoleForm, RoleQuery, RoleVO } from '/@/api/system/role/types'
import { RoleMenuTree } from '/@/api/system/menu/types.ts'
import { UserQuery, UserVO } from '/@/api/system/user/types'

// 角色 API
export const ApiSysRole: any = {}

ApiSysRole.page = (queryParam?: RoleQuery): Promise<PageResult<RoleVO[]>> => {
  return http.get('/sysRole/page', queryParam)
}

/**
 * 新增
 * @param data
 */
ApiSysRole.save = (data: RoleForm) => {
  return http.post('/sysRole/save', data)
}

/**
 * 修改
 * @param data
 */
ApiSysRole.update = (data: RoleForm) => {
  return http.post('/sysRole/update', data)
}

/**
 * 删除
 * @param id
 */
ApiSysRole.remove = (id: string | number | Array<string | number>) => {
  return http.post('/sysRole/remove/' + id)
}

/**
 * 状态修改
 * @param roleId ID
 * @param status 状态
 */
ApiSysRole.changeStatus = (roleId: number | string, status: string) => {
  const data = {
    roleId,
    status
  }
  return http.post('/sysRole/changeStatus', data)
}

/**
 * 查询角色已授权用户列表
 */
ApiSysRole.authUserAllocatedList = (query: UserQuery): Promise<UserVO[]> => {
  return http.get('/sysRole/authUser/allocatedList', query)
}

/**
 * 查询角色未授权用户列表
 */
ApiSysRole.authUserUnAllocatedList = (query: UserQuery): Promise<UserVO[]> => {
  return http.get('/sysRole/authUser/unAllocatedList', query)
}

/**
 * 取消用户授权角色
 */
ApiSysRole.authUserCancel = (data: any) => {
  return http.postParams('/sysRole/authUser/cancel', data)
}

/**
 * 批量取消用户授权角色
 */
ApiSysRole.authUserCancelAll = (data: any) => {
  return http.postParams('/sysRole/authUser/cancelAll', data)
}

/**
 * 提交授权用户
 */
ApiSysRole.authUser = (params: any) => {
  return http.postParams('/sysRole/authUser', params)
}

/**
 * 提交角色菜单权限
 */
ApiSysRole.authMenu = (data: RoleForm) => {
  return http.post('/sysRole/authMenu', data)
}

/**
 * 提交角色数据权限
 */
ApiSysRole.authDataScope = (data: RoleForm) => {
  return http.post('/sysRole/authDataScope', data)
}

// 根据角色ID查询菜单下拉树结构
ApiSysRole.menuTreeChecked = (roleId: string | number): Promise<RoleMenuTree> => {
  return http.get('/sysRole/menuTreeChecked/' + roleId)
}

/**
 * 根据角色ID查询部门树结构
 * @param roleId
 */
ApiSysRole.deptTreeChecked = (roleId: string | number): Promise<RoleDeptTree> => {
  return http.get('/sysRole/deptTreeChecked/' + roleId)
}

/**
 * 获取角色选择框列表 (目前使用：用户添加对话框)
 */
ApiSysRole.pageOptionSelect = (pageQuery: any): Promise<any> => {
  return http.get('/sysRole/pageOptionSelect', pageQuery)
}
